//package com.angel.bo.auth.client.config.security.handler;
//
//import com.alibaba.fastjson.JSON;
//import com.angel.bo.common.msg.WebReturn;
//import org.springframework.http.HttpStatus;
//import org.springframework.security.authentication.BadCredentialsException;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * @author zhangwei
// * @date 2018/4/26 16:30
// * @desc 自定义登录失败的时间监听, 返回json提示, 代替默认的页面跳转
// */
//@Component
//public class LoginFaildEnventHandler extends SimpleUrlAuthenticationFailureHandler {
//
//    @Override
//    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
//                                        AuthenticationException e) throws IOException, ServletException {
//        String message = "登录失败";
//        if (e instanceof BadCredentialsException) {
//            message = "密码错误";
//        } else if (e instanceof UsernameNotFoundException) {
//            message = "用户名不存在";
//        }
//
//        WebReturn<Object> messageModel = new WebReturn<>(HttpStatus.UNAUTHORIZED.value() + "", message);
//        response.setStatus(HttpStatus.UNAUTHORIZED.value());
//        response.setHeader("Content-Type", "application/json;charset=utf-8");
//        response.getWriter().print(JSON.toJSONString(messageModel));
//        response.getWriter().flush();
//    }
//}
